<?php

class Midia extends AppModel {
    var $name = 'Midia';

	public $belongsTo = array(
        'Produto' => array(
            'className' => 'Produto',
            'foreignKey' => 'produto_id'
        )
    );
	
	public function beforeDelete($cascade = true) {
		$midia = (empty($this->data))?$this->read():$this->data;
		
		$this->nome = $midia['Midia']['nome'];
		
		return true;
	}
	
	public function afterDelete($cascade = true) {
		$file = new File(WWW_ROOT . "img" . DS . $this->nome, false, 0777);
		$thumb = new File(WWW_ROOT . "img" . DS . 'thumb-'.$this->nome, false, 0777);
		
		$file->delete();
		$thumb->delete();
	}

}

?>
